package com.example.demo.mapper;

import com.example.demo.model.BookInfo;
import com.example.demo.model.PageRequest;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookInfoMapper {
    @Select("select * from book_info where status!=0 limit #{offset}, #{pageSize}")
    List<BookInfo> getBookInfos(PageRequest pageRequest);

    @Select("select count(*) from book_info where status!=0")
    Integer getCount();

    @Insert("insert into book_info(book_name, author, count, price, publish, `status`) " +
            "values(#{bookName}, #{author}, #{count}, #{price}, #{publish}, #{status})")
    Integer addBookInfo(BookInfo bookInfo);

    @Select("select * from book_info where id=${id}")
    BookInfo getBookById(Integer id);

    Integer update(BookInfo bookInfo);

    @Delete("update book_info set status=0 where id=#{id}")
    Integer deleteById(Integer id);

    Integer deleteByBatch(List<Integer> ids);
}
